package com.bhs.sansonglogistics.utils;

import android.content.Context;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;

import com.bhs.sansonglogistics.R;

import java.io.IOException;

public class VoiceUtils {
    private static MediaPlayer newOrder;
    private static final Uri newOrderUri=Uri.parse("android.resource://com.bhs.sansonglogistics/" + R.raw.new_order);

    //新订单通知
    public static void newOrder(Context context) {
        if (newOrder == null) {
            newOrder = new MediaPlayer();
            AudioAttributes attributes = new AudioAttributes.Builder()
                    .setLegacyStreamType(AudioManager.STREAM_MUSIC)
                    .build();
            newOrder.setAudioAttributes(attributes);
            try {
                newOrder.setDataSource(context, newOrderUri);
                newOrder.prepare();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        newOrder.start();
    }

    private static MediaPlayer orderSuccess;
    private static final Uri orderSuccessUri=Uri.parse("android.resource://com.bhs.sansonglogistics/" + R.raw.order_success);

    //抢单成功
    public static void orderSuccess(Context context) {
        if (orderSuccess == null) {
            orderSuccess = new MediaPlayer();
            AudioAttributes attributes = new AudioAttributes.Builder()
                    .setLegacyStreamType(AudioManager.STREAM_MUSIC)
                    .build();
            orderSuccess.setAudioAttributes(attributes);
            try {
                orderSuccess.setDataSource(context, orderSuccessUri);
                orderSuccess.prepare();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        orderSuccess.start();
    }

    private static MediaPlayer orderReceiving;
    private static final Uri orderReceivingUri=Uri.parse("android.resource://com.bhs.sansonglogistics/" + R.raw.order_receiving);

    //接单成功
    public static void orderReceiving(Context context) {
        if (orderReceiving == null) {
            orderReceiving = new MediaPlayer();
            AudioAttributes attributes = new AudioAttributes.Builder()
                    .setLegacyStreamType(AudioManager.STREAM_MUSIC)
                    .build();
            orderReceiving.setAudioAttributes(attributes);
            try {
                orderReceiving.setDataSource(context, orderReceivingUri);
                orderReceiving.prepare();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        orderReceiving.start();
    }
}
